﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TeachingAffairsManagementSystem.WebControl;

namespace TeachingAffairsManagementSystem
{
    public partial class Register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }


        protected void BtnRegister_Click(object sender, EventArgs e)
        {
            string username = TBUsername.Text;
            string password = TBPassword.Text;
            string email = TBEmail.Text;
            string name = TBName.Text;
            char gender = RMale.Checked ? '男' : '女';

            // 检查用户名是否可用
            if (!Operation.IsUsernameAvailable(username))
            {
                // 不可用
                Alert.Show("用户名已被使用", AlertBox.Level.Danger, true);
                return;
            }


            // 注册
            if (Operation.Register(username, password, email, name, gender))
            {
                // 注册成功 定时跳转
                Alert.Show("注册成功，5秒后跳转到登录页", AlertBox.Level.Success, true);
                TRedirect.Interval = 5000;
                TRedirect.Enabled = true;
            }
            else
            {
                // 注册失败
                Alert.Show("注册失败，请重试", AlertBox.Level.Danger, true);
            }
        }

        protected void TRedirect_Tick(object sender, EventArgs e)
        {
            Response.Redirect("~/Login.aspx");
        }
    }
}